<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>创建节点</title>
</head>
<body>
    
</body>
<script  type="text/javascript">
    var comentnode=document.createComment("这是一个注释");
    var divelementnode=document.createElement("div");
    var divclassattr=document.createAttribute("class");
    divclassattr.value="onediv";
    divelementnode.setAttributeNode(divclassattr);
    divelementnode.setAttribute("id","onediv");
    var pelementnode=document.createElement("p");
    var ptextnode=document.createTextNode("我是p");
    pelementnode.appendChild(ptextnode);
    divelementnode.appendChild(pelementnode);
    var body=document.body;
    body.appendChild(divelementnode);
    body.appendChild(comentnode);


    var docfragment=document.createDocumentFragment();
    var divtwonode=document.createElement("div");
    var textnodetwo=document.createTextNode("我是第二个div");
    divtwonode.appendChild(textnodetwo);
    docfragment.appendChild(divtwonode);
    body.appendChild(docfragment);
</script>
</html>